<?php
/*********************************************************************\
* This File is a part of BH-PANEL (Breizh-Heberg Panel v2.1)
* Copyright (C) 2008-2009 the BH Developpers : Vincent Giersch <mail@vincordi.fr>, Cyprien Laleau <fanning.fr@gmail.com> and Edwin Cabiten <marmottes44@hotmail.fr>
* See file AUTHORS to get more informations

* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.

* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.

* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
/*********************************************************************/


define('CONFIG_ROOT', '/etc/bh/');
define('CODE_ROOT', '/opt/hosting/daemons/includes/');
define('CURRENT_SERVER', 4);
define('PARTITION', '/');
define('APACHE_CONF', CONFIG_ROOT.'serveurs/data_apache/_apache2.conf');
include CODE_ROOT."common.php";
//////////////////////////////////////////////////////
$headers = "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=utf-8\n";
$headers .= "From: Breizh Héberg Bot <robot@breizh-heberg.net>\n";
$headers .= "Reply-To: Support Breizh-Héberg <support@breizh-heberg.net>\n";
//////////////////////////////////////////////////////
// --------------------------- Comptes  d'Hébergement
$liste_ = query("SELECT 
				comptes_heberg.*,
				UNIX_TIMESTAMP(comptes_heberg.expire)
				FROM comptes_heberg
				WHERE etat = '1' AND serveur_apache = '".CURRENT_SERVER."'");
While($liste = mysql_fetch_array($liste_)) {
	$size = du("/home/".$liste['user_linux']);
	$bp = shell_exec("cat ".CONFIG_ROOT."serveurs/logs_apache/archives/access-".$liste['user_linux'].".log | awk '{ TOTAL+=$1 } END { print TOTAL }'");
	shell_exec("sudo cat ".CONFIG_ROOT."serveurs/logs_apache/access-".$liste['user_linux'].".log > ".CONFIG_ROOT."serveurs/logs_apache/archives/access-".$liste['user_linux'].".log");
	shell_exec("sudo rm ".CONFIG_ROOT."serveurs/logs_apache/access-".$liste['user_linux'].".log");
	echo $bp."\n";
	if(trim($bp) == "") { $bp = 0; }
	query("UPDATE comptes_heberg SET espacedisk = '".$size."', bandepassante = bandepassante + $bp WHERE id = '".$liste['id']."'");
}
shell_exec("sudo apache2ctl graceful");	
deconnexionbdd();
?>
